{% extends "layouts/bbs.html" %}
{% load navtag %}
{% block nav %}
  {% nav "cooperate" %}
  {{ block.super }}
{% endblock %}

{% block content %}
  <script src="/static/plugin/ckeditor/ckeditor-init.js"></script>
  <script src="/static/plugin/ckeditor/ckeditor/ckeditor.js"></script>
  <h1 style="text-align: center;padding-bottom: 30px;">{{ bbs.title }}</h1>
  <div class="col-md-12">
    <span class="label label-rouded label-success">作者：
      {% if bbs.anonymous %} 匿名 {% else %} {{ bbs.user.username }} {% endif %}
      </span>
    <span class="label label-rouded label-info">板块：{{ bbs.type }}</span>
    <span class="label label-rouded btn-primary">评论：{{ count }}</span>
    <span class="time pull-right">{{ bbs.create_time }}</span>
  </div>
  <div class="col-md-12" style="border-bottom: 1px solid #e1e8ed; margin: 30px 0px; padding-bottom: 30px;">
    {{ bbs.content | safe }}
  </div>
  <div class="col-md-12">
    {% include 'bbs/get_comments.html' %}
  </div>
  <div class="col-md-12">
    <a href="javascript:;" class="next_page">查看更多</a>
  </div>
  <form action="new_comment" method="post" class="comment">
    <input type="hidden" value="{{ request.user.pk }}" , name="user">
    <input type="hidden" value="{{ bbs.id }}" , name="bbs">
    <div class="col-md-12">
      {{ comment.content }}
    </div>
    <div class="pull-right" style="margin-top: 15px;">
      <a class="btn btn-info submit">回复</a>
    </div>
  </form>
  <input type="hidden" class="cur_page" value= 1>
  <script>
      $('.submit').click(function () {
          $('#id_content').val(CKEDITOR.instances.id_content.document.getBody().getText());
          $.ajax({
              url: '/bbs/new_comment',
              type: 'post',
              data: $(this).closest('form').serialize(),
              success: function (data) {
                  if (data.msg == 'true') {
                      alert(data.result);
                  } else {
                      $('.new_comment').append(data);
                      CKEDITOR.instances.id_content.document.getBody().setText()
                  }
              }
          });
      });
      $('.next_page').click(function () {
          var cur_page = parseInt($('.cur_page').val()) + 1;
          $('.cur_page').val(cur_page);
          $.ajax({
              url: '/bbs/ajax_comments/' + '{{ bbs.pk }}' + '?page=' + cur_page,
              type: 'get',
              success: function (data) {
                  if (data.msg == 'true') {
                      $(this).text("没有更多评论！");
                  } else {
                      $('.add_more').append(data)
                  }
              }
          })
      })
  </script>
  <style>
    .comment-center .comment-body:hover {
      background: #FFFFFF;
    }
  .comment-body .user-img h5.user-name{text-align: center;margin-top: 15px;}
  .comment-center .user-img{ width: 80px; padding: 0px 10px;}
  </style>
{% endblock %}